<?php
namespace app\beautiful\logic;
use app\beautiful\model\member\MemberModel;
use app\beautiful\model\LevelModel;
//用户等级
class MemberLevelLogic{
   
   //等级是充值金额和积分
   public static  function level($shopId,$memberId,$balance = 0 ,$integral = 0){
       $member = MemberModel::find($memberId);
       if(null === $member) return false;
       if($member->shop_id != $shopId) return false;
       $member->rank_num = $member->rank_num + $integral;
       $member->recharge = round(($member->recharge *100 + $balance * 100)/100,2);
       
       if(null !== $Level = LevelModel::where([
           ['shop_id','=',$shopId]
       ])->whereRaw("need_integral <= :rank or need_recharge <= :recharge ",['rank'=>$member->rank_num,'recharge' => $member->recharge])->order(['vip_level'=>'desc'])->find()){
           $member->level_id = $Level->level_id;
       }
       $member->save();
       return  true;
   }    
}